package com.tiamosu.navigation.demo.ui.fragments

import android.os.Bundle
import android.util.Log
import androidx.core.os.bundleOf
import com.tiamosu.databinding.delegate.lazyDataBinding
import com.tiamosu.databinding.page.DataBindingConfig
import com.tiamosu.navigation.demo.R
import com.tiamosu.navigation.demo.base.BaseFragment
import com.tiamosu.navigation.demo.databinding.FragmentDBinding
import com.tiamosu.navigation.demo.ext.jumpFragment

/**
 * @author tiamosu
 * @date 2021/5/7.
 */
class DFragment : BaseFragment() {
    private val dataBinding: FragmentDBinding by lazyDataBinding {
        Log.e("susu", "onViewDestroyed")
    }

    private var count = 0

    companion object {
        private const val TAG_PARAM = "TAG_PARAM"
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.fragment_d)
    }

    override fun onNewBundle(args: Bundle?) {
        super.onNewBundle(args)
        val data = args?.getInt(TAG_PARAM)
        Log.e("susu", "bundle:$args   data:$data")
    }

    override fun doBusiness() {
        dataBinding.dBtnJumpTest.setOnClickListener {
            count++
            jumpFragment(
                R.id.dFragment,
                singleTop = true,
                args = bundleOf(TAG_PARAM to count)
            )
        }

        dataBinding.dBtnSharedViewModelUse.setOnClickListener {
            sharedViewModel.selectTabItem.value = BFragment::class.java
            jumpFragment(popUpToId = R.id.mainFragment)
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        Log.e("susu", "onDestroyView")
    }
}